package com.litq.education.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.litq.education.bean.CustomerTable;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * CustomerMapper
 *
 * @author litq
 * @version v1.0
 * @since 2019/2/10 1:31
 */
@Mapper
public interface CustomerMapper extends BaseMapper<CustomerTable> {
    /**
     * @param page 页码
     * @param id
     * @Method 页面查询客户所有信息
     * @Author Litq
     * @Version 1.0
     * @Description 查询客户所有信息
     * @since 2019/8/16
     */
    @Select("SELECT c.id,c.user_name,c.school,c.grade,c.parent_name,c.parent_phone,c.is_cap,c.sex,g.group_name,g.group_address,g.create_date,g.pintuanbeg_date,g.pintuanend_date,g.groupbeg_date,g.pintuan_count FROM `group_table` g , customer_table c where g.id = c.group_id")
    List<Map<String, Object>> dyGetUserList(Page<Map<String, Object>> page, Integer id);


    /**
     * @param username 姓名
     * @Method 页面查询客户所有信息
     * @Author Litq
     * @Version 1.0
     * @Description 查询客户所有信息
     * @since 2019/8/16
     */
    @Select("SELECT c.id,c.user_name,c.school,c.grade,c.parent_name,c.parent_phone,c.is_cap,c.sex,g.group_name,g.group_address,g.create_date,g.pintuanbeg_date,g.pintuanend_date,g.groupbeg_date,g.pintuan_count FROM `group_table` g ,customer_table c where g.id = c.group_id and user_name = #{username}")
    List<Map<String, Object>> dyGetUserListByUsername(String username);

    /**
     * @Method 查询数据总条数
     * @Author Litq
     * @Version 1.0
     * @Description 查询数据总条数
     * @since 2019/8/16
     */
    @Select("select count(*) from `customer_table` ")
    int count();

    /**
     * @Method 查询groupid总条数
     * @Author Litq
     * @Version 1.0
     * @Description 查询数据总条数
     * @since 2019/8/16
     */
    @Select("select count(*) from `customer_table` where group_id = #{group_id} ")
    int countByGroupId(String group_id);

    /**
     * @Method 根据groupid查询设定人数
     * @Author Litq
     * @Version 1.0
     * @Description 根据groupid查询设定人数
     * @since 2019/8/16
     */
    @Select("select zong_count from `group_table` where id = #{group_id} ")
    int zongCountByGroupId(String group_id);

    @Update("update `group_table` set pintuan_count = #{count} ")
    int updateCount(int count);

    @Select("select * from `customer_table`  where id = #{group_id} and is_cap = 1 ")
    Map selectIsCap(String group_id);
}